﻿using System.Collections.ObjectModel;
using System.Threading.Tasks;
using Infos.InterviewApp.InfoAppService;
using LibQuestionIs.Models;

namespace Infos.InterviewApp.Manager
{
    public class ManagerServices : BaseManager
    {
        public async Task GetDatiService(int version)
        {
            if (DataFlowObject.ListTipologiaTest == null)
            {
                QuizServiceClient client = new QuizServiceClient();

                GetTipologieAndDifficoltaResponse response = await client.GetTipologieAndDifficoltaAsync(new GetTipologieAndDifficoltaRequest() { Version = version });
                DataFlowObject.ListTipologiaTest = new ObservableCollection<TipologiaTest>();
                foreach (var item in response.ListTipologie)
                    DataFlowObject.ListTipologiaTest.Add(new TipologiaTest()
                    {
                        IDTest = item.IdTipologiaTest,
                        NomeTest = item.Descrizione
                    });
                DataFlowObject.ListDifficolta = new ObservableCollection<Difficolta>();
                foreach (var item in response.ListDifficolta)
                    DataFlowObject.ListDifficolta.Add(new Difficolta()
                    {
                        IDDifficolta = item.IDDifficolta,
                        NumMaxDomande = item.NumMaxDomande,
                        TempoMaxDomande = item.TempoMaxDomande,
                        Punteggio = item.Punteggio,
                        Titolo = item.Titolo
                    });
                DataFlowObject.Version = response.Version;
                DataFlowObject.UpdateDifficolta = response.UpdateDifficolta;
                DataFlowObject.UpdateDomande = response.UpdateDomande;
                DataFlowObject.UpdateTipologia = response.UpdateTipologie;
                DataFlowObject.InfoBacheca = response.InfoBacheca;
            }
        }
    }
}
